package net.bbtang.website.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import net.bbtang.website.bean.UserGroupBean;
import net.bbtang.website.mapper.GroupMapper;
import net.bbtang.website.mapper.GroupMealMapper;
import net.bbtang.website.pojo.UserGroupDTO;
import net.bbtang.website.pojo.UserGroupMealDTO;
import net.bbtang.website.service.GroupInfoService;




@Service("groupInfoService")
public class GroupInfoServiceImpl implements GroupInfoService {
	
	private static final Logger logger = Logger.getLogger(GroupInfoServiceImpl.class);
	
	@Autowired
	GroupMapper groupMapper;
	@Autowired
	GroupMealMapper groupMealMapper;

	@Override
	public List<UserGroupBean> getGroupInfoByUniversity(String universityId,int groupType) {
		Map<String,Object> map =new HashMap<String, Object>();
		map.put("universityId", universityId);
		map.put("groupType", groupType);
		List<UserGroupDTO> userGroupList =  groupMapper.getGroupInfoById(map);
		
		List<UserGroupBean> userGroupBeanList =  new ArrayList<UserGroupBean>();
		if(userGroupList != null && userGroupList.size() > 0){
			for (UserGroupDTO userGroupDTO : userGroupList) {
				UserGroupBean userGroupBean = new UserGroupBean();
				userGroupBean.setCreateTime(userGroupDTO.getCreateTime());
				userGroupBean.setGroupAdmin(userGroupDTO.getGroupAdmin());
				userGroupBean.setGroupName(userGroupDTO.getGroupName());
				userGroupBean.setId(userGroupDTO.getId());
				userGroupBean.setRemarks(userGroupDTO.getRemarks());
				userGroupBean.setUpdateTime(userGroupDTO.getUpdateTime());
				userGroupBean.setGroupInUniversity(userGroupDTO.getGroupInUniversity());
				Map<String,Object> mealMap = new HashMap<String, Object>();
				mealMap.put("groupId", userGroupDTO.getId());
				List<UserGroupMealDTO> userGroupMealList =  groupMealMapper.getGroupMeal(mealMap);
				userGroupBean.setUserGroupMeal(userGroupMealList);
				userGroupBeanList.add(userGroupBean);
				
			}
		}
		return userGroupBeanList;
	}

	@Override
	public List<UserGroupBean> getGroupInfoByid(Map<String, Object> map) {
		List<UserGroupDTO> groupList = groupMapper.getGroupInfoById(map);
		List<UserGroupBean> userGroupBeanList =  new ArrayList<UserGroupBean>();
		if(groupList != null && groupList.size() > 0){
			for (UserGroupDTO userGroupDTO : groupList) {
				UserGroupBean userGroupBean = new UserGroupBean();
				userGroupBean.setCreateTime(userGroupDTO.getCreateTime());
				userGroupBean.setGroupAdmin(userGroupDTO.getGroupAdmin());
				userGroupBean.setGroupName(userGroupDTO.getGroupName());
				userGroupBean.setId(userGroupDTO.getId());
				userGroupBean.setRemarks(userGroupDTO.getRemarks());
				userGroupBean.setUpdateTime(userGroupDTO.getUpdateTime());
				userGroupBean.setGroupInUniversity(userGroupDTO.getGroupInUniversity());
				Map<String,Object> mealMap = new HashMap<String, Object>();
				mealMap.put("groupId", userGroupDTO.getId());
				List<UserGroupMealDTO> userGroupMealList =  groupMealMapper.getGroupMeal(mealMap);
				userGroupBean.setUserGroupMeal(userGroupMealList);
				userGroupBeanList.add(userGroupBean);
			}
		}
		return userGroupBeanList;
	}


	


}
